package com.xxx.rpc.client.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

/**
 * Created by admin on 2019/1/4.
 */
public class PropertiesUtils {
    private static String PROPERTY_NAME = "rpc.properties";

    public static Object getCommonYml(Object key){
        Properties properties = getProperties();
        return properties.get(key);
    }
    
    public static boolean exitsRpcFile(){
        return getProperties()!=null;
    }


    public static Properties getProperties() {
   	 try {
		return PropertiesLoaderUtils.loadAllProperties(PROPERTY_NAME);
	} catch (IOException e) {
		e.printStackTrace();
	}
	return null;
   }

	public static List<String> getArrayYml(String key) {
		String value=(String) getCommonYml(key);
		if("".equals(value)||null==value) {
			return null;
		}
		List<String> array=new ArrayList<String>();
		String[] values=value.split(",");
		for (int i = 0; i < values.length; i++) {
			array.add(values[i]);
		}
        return array;
	}
}